package com.yangzheandroid.rxmvp.base;

import rx.Subscription;
import rx.subscriptions.CompositeSubscription;

public class RxPresenter<T extends BaseView> implements BasePresenter<T> {

    protected T mView;
    public CompositeSubscription mCompositeDisposable ;

    protected void unSubscribe() {
        if (mCompositeDisposable != null) {
            mCompositeDisposable.unsubscribe();
        }
    }

    protected void addSubscribe(Subscription subscription) {
        if (mCompositeDisposable == null) {
            mCompositeDisposable = new CompositeSubscription();
        }
        mCompositeDisposable.add(subscription);
    }



    @Override
    public void attachView(T view) {
        this.mView = view;
    }

    @Override
    public void detachView() {
        this.mView = null;
        unSubscribe();
    }
}